<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<script type="text/javascript">
	$(function(){		
		function getItems(market){
			$('#categoryItems').empty();			
			$.getJSON('<%= request.getContextPath()%>/setCategories.do',	//url 호출
			{								//데이터 전달
				market:market
			},function(data){				//서버응답시 실행할 function
				$(data).each(function(index, item){					
					var output = '';
					output += '<option value="'+item.c_code+'">'+item.category+'</option>';
					$('#categoryItems').append(output);					
				});
			});
		}
		
		$('#marketType').change(function(){
			getItems($('#marketType').val());
		});
		
		$('#marketType [value="${searchMarket}"]').attr("selected","selected");
		$('#categoryItems [value="${searchCategory}"]').attr("selected","selected");
	});
</script>
<div class="detail">
<form:form enctype="multipart/form-data" action="productWrite.do" commandName="command">
	<fieldset>
		<legend>상품등록</legend>
		<input type="hidden" name="pageNum" value="${pageNum}">
		<input type="hidden" name="searchMarket" value="${searchMarket}">
		<input type="hidden" name="searchCategory" value="${searchCategory}">
		<table>
			<tr>
				<td><label for="c_code">대분류 : </label></td>
				<td>
					<select id="marketType">					
					<option value="outer">OUTER</option>
					<option value="top">TOP</option>
					<option value="bottom">BOTTOM</option>
					<option value="dress">DRESS</option>
					<option value="shoes">SHOES</option>
					<option value="accessary">ACCESSARY</option>
				</select>
				</td>
			</tr>
			<tr>
				<td><label for="c_code">카테고리 :</label></td>
				<td>
					<form:select path="c_code" name="c_code" id="categoryItems">
					<c:forEach	var="i" items="${defCategory}">
						<form:option value="${i.c_code}" label="${i.category}"></form:option>
					</c:forEach>					
				</form:select>		
				</td>
			</tr>
			<tr>
				<td><label for="product">상품명 :</label></td>
				<td>
					<form:input path="product"/>
					<form:errors path="product"/>
				</td>
			</tr>
			<tr>
				<td><label for="content">상품설명 :</label></td>
				<td>
					<form:input path="content"/>
					<form:errors path="content"/>
				</td>
			</tr>
			<tr>
				<td><label for="price">가격 :</label></td>
				<td>
					<form:input path="price"/>
					<form:errors path="price"/>
				</td>
			</tr>
			<tr>
				<td><label for="point">포인트 :</label></td>
				<td>
					<form:input path="point"/>
					<form:errors path="point"/>
				</td>
			</tr>
			<tr>
				<td colspan="2"><label for="upload">이미지 :</label></td>				
			</tr>
			<tr>
				<td colspan="2"><input type="file" class="multi" name="upload" id="upload"></td>
			</tr>
			<tr>
				<td><label for="show">표시여부 :</label></td>
				<td>
					<form:radiobutton path="show" value="y" label="공개" checked="checked"/>
					<form:radiobutton path="show" value="n" label="비공개"/>
				</td>
			</tr>
		</table>		
	</fieldset>
	<input type="submit" value="등록">
				<input type="button" value="취소" onclick="history.go(-1)">
</form:form>
</div>